import re
f1=open("req.txt","r",encoding="UTF-8")
f1txt=f1.read()
f1.close()
pattern = re.compile(r'(?<=>)[^\n].+\d*(?=</span>)')
a=0
b=2
jg=[]
for i in pattern.findall(f1txt)[30:]:
    if i !="Counter-Strike: Global Offensive":
        if "¥" in i:
            a+=1
            if a==2:
                a=0
                continue
        if b==2:
            b=0
            continue
        if "&" in i:
            break  
        jg.append(i)
        b+=1
jgb=[]
for k in jg:
    print(k)
    if "StatTrak" in k:
        continue
    if "破损" in k:
        jgb.append(float(jg[jg.index(k)-1].strip("¥ ")))
    if "战痕" in k:
        jgb.append(float(jg[jg.index(k)-1].strip("¥ ")))
    if "久经" in k:
        jgb.append(float(jg[jg.index(k)-1].strip("¥ ")))
    if "略有" in k:
        jgb.append(float(jg[jg.index(k)-1].strip("¥ ")))
    if "崭新" in k:
        jgb.append(float(jg[jg.index(k)-1].strip("¥ ")))
else:
    jgb.insert(0,jg[1].replace(" ","").strip(" ").split("(")[0])
while True:
    zu=input("请输入合成组名(不知道请填A):").upper()
    if(zu!=""):
        break
last=1

with open("jgb"+zu+".txt","r") as f:
    ff=f.readlines()
fg=[]
for i in ff:
    fg.append(i.strip("\n"))
ff=open("jgb"+zu+".txt","w")
for i in range(len(fg)):
    if(len(fg[i])>1):
        ff.write(fg[i]+"\n")
ff.close()



with open("jgb"+zu+".txt","r") as f:
    last=int(list(f.readlines()[-1])[1])+1
txt=zu+str(last)+"="+str(jgb)+"\n"
txt=txt.replace("'","\"").replace(", ",",").replace(" ","-")

f12=open("jgb"+zu+".txt","r")
f1=f12.readlines()
f12.close()

xgm=0
for dqz in f1:
    if jgb[0] in dqz:
        print("修改前:"+dqz.strip("\n"))
        txt=txt.replace(txt.split("=")[0],dqz.split("=")[0]).strip("\n")
        print("修改后:"+txt)
        xz=input("是否修改?默认T,取消F:")
        if(xz=="F"):
            break
        f1[f1.index(dqz)]=txt
        f13=open("jgb"+zu+".txt","w")
        for i in f1:
            f13.write(i.strip("\n")+"\n")
        print("已写入")
        f13.close()
        xgm=1
if(xgm==0):
    print(txt)
    a=input("未找到相同值，是否写入新条目？(取消输入F):").upper()
    if(a!="F"):
        f12=open("jgb"+zu+".txt","a")
        f12.write(txt)
        f12.close()
        print("已写入")
